#pragma once
#include "base/noncopyable.h"

#include <pthread.h>
namespace net_tools{
namespace base{

class Mutex : noncopyable
{
 public:
  Mutex(){
    pthread_mutex_init(&mutex_,NULL);
  };
  ~Mutex(){
    pthread_mutex_destroy(&mutex_);
  };
  void Lock(){
    pthread_mutex_lock(&mutex_);
  }
  void Unlock(){
    pthread_mutex_unlock(&mutex_);
  }
  pthread_mutex_t* Get_mutex(){ return &mutex_;}
 private:
  pthread_mutex_t mutex_;
};
} // namespace base

class MutexLock : base::noncopyable{
 public:
  explicit MutexLock(net_tools::base::Mutex& mutex):mutex_(mutex){
    mutex_.Lock();
  }
  ~MutexLock(){
    mutex_.Unlock();
  }
 private:
  base::Mutex& mutex_;
};

} // namespace net_tools